/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.ui.util;

import java.awt.Container;
import java.io.File;
import java.io.IOException;

public abstract class BaseUIHelper {

    protected MiscUIHelper miscUIHelper =new MiscUIHelper();	
	
	private static String tmapDir =null;
	
	private static File tmaDir =null;
	private static File bmaDir =null;
	private static File dataDir =null;
	private static File cdDir =null;
	private static File annDir =null;
	
	/**
	 * Returns the directory prepended with the TMap user home directory
	 * Creates the TMap directory structure if necessary
	 * @param dir the target directory
	 * @return
	 */
	protected File getTMapDir( Container container, File dir ) {
		if ( tmapDir == null ) {
			try {
				tmapDir = new UserHomeHelper().getTMapDir();
			} catch (IOException e) {
				miscUIHelper.displayErrorMessage( container, e );
			}
		}
		
		return new File( tmapDir + dir.getName() );
	}
	
	protected static void setTmaDir( File dir ) {
		BaseUIHelper.tmaDir =dir;
	}
	
	protected File getTmaDir( Container container ) {
		if ( tmaDir == null ) {
			try {
				tmaDir = new File( new UserHomeHelper().getTMapDir() + FileChooserFilter.TMAPS_DIR );
			} catch (IOException e) {
				miscUIHelper.displayErrorMessage( container, e );
			}
		}
		
		return tmaDir;
	}

	protected static void setBmaDir(File dir) {
		BaseUIHelper.bmaDir = dir;
	}
	
	protected File getBmaDir( Container container ) {
		if ( bmaDir == null ) {
			try {
				bmaDir = new File( new UserHomeHelper().getTMapDir() + FileChooserFilter.MAPS_DIR );
			} catch (IOException e) {
				miscUIHelper.displayErrorMessage( container, e );
			}
		}
		
		return bmaDir;
	}	

	protected static void setDataDir(File dir) {
		BaseUIHelper.dataDir = dir;
	}
	
	protected File getDataDir( Container container ) {
		if ( dataDir == null ) {
			try {
				dataDir = new File( new UserHomeHelper().getTMapDir() + FileChooserFilter.DATA_DIR );
			} catch (IOException e) {
				miscUIHelper.displayErrorMessage( container, e );
			}
		}
		
		return dataDir;
	}		

	protected static void setCdDir(File dir) {
		BaseUIHelper.cdDir = dir;
	}
	
	protected File getCdDir( Container container ) {
		if ( cdDir == null ) {
			try {
				cdDir = new File( new UserHomeHelper().getTMapDir() + FileChooserFilter.CDS_DIR );
			} catch (IOException e) {
				miscUIHelper.displayErrorMessage( container, e );
			}
		}
		
		return cdDir;
	}	

	protected static void setAnnDir(File dir) {
		BaseUIHelper.annDir = dir;
	}	
	
	protected File getAnnDir( Container container, File dir ) {
		if ( annDir == null ) {
			try {
				annDir = new File( new UserHomeHelper().getTMapDir() + FileChooserFilter.ANNOTATIONS_DIR );
			} catch (IOException e) {
				miscUIHelper.displayErrorMessage( container, e );
			}
		}
		
		return annDir;
	}	
	
}
